local skill = fk.CreateSkill{
  name = "tea__yanzhong",
}
---@type TrigSkelSpec<TrigFunc>
local yanzhong = {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill then
      return false
    else
      return player:hasSkill(self) and target == player and table.find(player.room:getOtherPlayers(player), function(p)
        return not p:hasSkill(skill.name, true)
      end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventAcquireSkill then
      return true
    else
      local targets = table.filter(room:getOtherPlayers(player), function(p)
        return not p:hasSkill(self, true)
      end)
      if #targets > 0 then
        local to, cids, suc = room:askToChooseCardsAndPlayers(player, {
          targets = targets,
          min_card_num = 1,
          max_card_num = 1,
          min_num = 1,
          max_num = 1,
          skill_name = skill.name,
          prompt = "#tea__yanzhong-invoke"
        })
        if suc and #to == 1 and #cids == 1 then
          event:setCostData(self, {to[1], cids[1]})
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventAcquireSkill then
      player:drawCards(1, self.name)
    else
      local to = event:getCostData(self)[1]
      local cid = event:getCostData(self)[2]
      room:obtainCard(to, cid, false, fk.ReasonGive, player)
      room:handleAddLoseSkills(to, skill.name, nil, false)
      for _, p in ipairs(room:getOtherPlayers(to)) do
        if p:hasSkill(skill.name) then
          p:drawCards(1, skill.name)
        end
      end
    end
  end,
}
skill:addEffect(fk.Damage, yanzhong)
skill:addEffect(fk.Damaged, yanzhong)
skill:addEffect(fk.EventAcquireSkill, yanzhong)
return skill